package com.deep.spring.v18;

import org.eclipse.jetty.util.BlockingArrayQueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TaskPoolExecutorExample {

    public static void main(String[] args) {
        int corePoolSize = 5;
        int maximumPoolSize = 20;
        long keepAliveTime = 20L;
        TimeUnit unit = TimeUnit.SECONDS;
        BlockingQueue<Runnable> workQueue = new BlockingArrayQueue<>(1000);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                unit,
                workQueue
        );

        for (int i = 0; i < 2000; i++) {
            threadPoolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("aaaaaaaaaaa" + Thread.currentThread().getName());
                }
            });
        }

    }
}
